var Shop = Class
		.extend({
			availableWeapons : [ new Pump(), new MachineGun(), new Sniper() ],
			initShop : function() {
				$(document).off();
				var availableMoney = player.money;
				var _this = this;
				var width = window.innerWidth;
				var top = 80;
				var left = (width / 2) - 400;
				for (var i = 0; i < this.availableWeapons.length; i++) {
					var element = $("<div>");
					element.css({
						position : 'absolute',
						float : 'left',
						width : '200px',
						height : '130px',
						top : top + 'px',
						left : left + 'px',
						backgroundColor : 'black',
						paddingLeft : '15px',
						fontSize : '25px',
						fontStyle : 'italic',
						borderTopLeftRadius : '25px',
						borderBottomLeftRadius : '25px',
						color : 'white'
					});
					element.html(this
							.getWeaponsProperties(this.availableWeapons[i]));
					$("body").append(element);

					var pic = $("<div>");
					pic.css({
						position : 'absolute',
						width : '500px',
						height : '130px',
						top : top + 'px',
						left : left + 200 + 'px',
						backgroundColor : 'black',
						paddingLeft : '15px',
						fontSize : '25px',
						fontStyle : 'italic',
						borderTopRightRadius : '25px',
						borderBottomRightRadius : '25px',
					});
					pic.append("<img src=" + this.availableWeapons[i].picture
							+ " height='115px'> ");

					$("body").append(pic);

					if (this.availableWeapons[i].haveIt == false) {
						var buy = $("<div>");
						buy.css({
							position : 'absolute',
							width : '110px',
							height : '130px',
							top : top + 'px',
							left : left + 720 + 'px',
							backgroundColor : 'green',
							borderRadius : '25px',
							textAlign : 'center',
							veticalAlign : 'middle',
							lineHeight : '130px',
							fontSize : '40px',
							fontStyle : 'italic',
							color : 'white'
						});
						buy.html('Buy');
						buy.attr('id', i);
						buy.addClass('BuyButton');
						$("body").append(buy);
					}
					var buy = $("<div>");
					buy.css({
						position : 'absolute',
						width : '110px',
						height : '130px',
						top : top + 'px',
						left : left + 870 + 'px',
						backgroundColor : 'green',
						borderRadius : '25px',
						textAlign : 'center',
						veticalAlign : 'middle',
						lineHeight : '130px',
						fontSize : '40px',
						fontStyle : 'italic',
						color : 'white'
					});
					buy.html('Ammo');
					buy.attr('id', i + 5);
					buy.addClass('BuyAmmo');
					$("body").append(buy);

					top += 150;
				}
				$('.BuyButton').hover(function() {
					$(this).css({
						"background-color" : "blue"
					});
				}, function() {
					$(this).css({
						"background-color" : "green"
					});
				});

				$('.BuyButton').mousedown(function(event) {
				});

				$('.BuyButton')
						.mousedown(
								function(event) {
									var index = parseInt(this.id);
									if (player.money >= _this.availableWeapons[index].price) {
										player.weapons
												.push(_this.availableWeapons[index]);
										player.money = player.money
												- _this.availableWeapons[index].price;
										_this.availableWeapons[index].haveIt = true;
									
										this.remove();

										Money.html('Available money: '
												+ player.money);
									} else {
										alert("Not enough money to buy this weapon!");
									}
								});

				$('.BuyAmmo').hover(function() {
					$(this).css({
						"background-color" : "blue"
					});
				}, function() {
					$(this).css({
						"background-color" : "green"
					});
				});

				$('.BuyAmmo')
						.mousedown(
								function(event) {
									var index = parseInt(this.id - 5);
									if (player.money >= _this.availableWeapons[index].ammoPrice) {
										player.money = player.money
												- _this.availableWeapons[index].ammoPrice;
										for (var i = 0; i < player.weapons.length; i++) {
											if (_this.availableWeapons[index].name == player.weapons[i].name) {
												if (player.weapons[i].extraMagazines < _this.availableWeapons[index].maxExtraMagazines) {
													player.weapons[i].extraMagazines++;
													Money
															.html('Available money: '
																	+ player.money);

												} else {
													alert("You can not carry more ammo!");
													break;
												}
											}
										}
									} else {
										alert("Not enough money to buy ammo!");
									}
								});

				var Money = $("<div>");
				$(".money").remove();
				Money.css({
					position : 'absolute',
					width : '300px',
					height : '55px',
					top : top + 'px',
					left : left + 220 + 'px',
					color : 'white',
					fontSize : '30px'
				});
				Money.html('Available money: ' + player.money);
				Money.addClass('money');
				$("body").append(Money);

				var NextLevel = $("<div>");
				NextLevel.css({
					position : 'absolute',
					width : '300px',
					height : '55px',
					top : top + 'px',
					left : left + 720 + 'px',
					"background-image" : "url('WebContent/img/leveling.png')",
					borderRadius : '25px',
					textAlign : 'center',
					veticalAlign : 'middle',
					lineHeight : '55px',
					fontSize : '40px',
					"font-family" : "impact",
					color : 'white'
				});
				NextLevel.html('Next Level > >');
				NextLevel.attr('id', i);
				NextLevel.addClass('LevelUP');
				$("body").append(NextLevel);
				$('.LevelUP').mousedown(function(event) {
					$("div").remove();
					for (var i = 0; i < player.weapons.length; i++) {
						player.weapons[i].shooting = false;
					}
					monsters = [];
					a.mobsKilled = 0;
					a.currentLevel++;
					if (a.currentLevel == 3) {
						a.mobsForLevelMax = 10000;
					}

					a.levelStart(a.levels[a.currentLevel]);

				});

			},

			getWeaponsProperties : function(weapon) {
				var string = "Max Bullets: " + weapon.maxBulletsInMagazine
						+ "<br>";
				string += "Reload Time: " + weapon.reloadTime + "<br>";
				string += "Price: " + weapon.price + "<br>";
				string += "Ammo Price: " + weapon.ammoPrice;
				return string;
			}
		});